package com.bonc.ioc.service.impl;

import com.bonc.ioc.base.service.BaseService;
import com.bonc.ioc.dao.HomePageMapper;
import com.bonc.ioc.service.HomePageService;
import com.bonc.ioc.vo.TopicVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.regex.Pattern;

/**
 * @author liuyang
 * @creats 2021-04-09-11:11
 */
@Service
public class HomePageServiceImpl extends BaseService implements HomePageService {
    @Resource
    HomePageMapper homePageMapper;

    private static final Pattern PATTERN = Pattern.compile("[0-9]*");

    @Override
    public Integer getVisitNum() {
        return homePageMapper.getVisitNum();
    }

    @Override
    public List<TopicVo> getSpecial(String pageSize, String pageNum) {
        if (StringUtils.isEmpty(pageSize) || !PATTERN.matcher(pageSize).matches()) {
            pageSize = "4";
        }
        if (StringUtils.isEmpty(pageNum) || !PATTERN.matcher(pageNum).matches()) {
            pageNum = "0";
        }
        Integer ps = Integer.parseInt(pageSize);
        Integer pn = Integer.parseInt(pageNum);
        return homePageMapper.getSpecial(ps, pn);
    }
}
